< previous page page_440 next page >

Page 440
9f31265bb40b592b1929e18a47ab28e5.gif
   End If
   If Trim$(txtLast) = "" Then
      txtLast.Tag = "ERROR"
   End If
   ' Check the Tag property in all controls
   boolFlag = False
   For Each ctlAny In Me.Controls
      If ctlAny.Tag = "ERROR" Then
         ctlAny.Text = conRequired
         ctlAny.Font.Italic = True
         boolFlag = True
      End If
   Next ctlAny

   If boolFlag Then
      MsgBox "The Fields Marked " & _
             conRequired & _
             " Must Be Filled In or Corrected"
   Else
      FormCheck = True
   End If
End Function
The FormCheck() function first clears all the Tag properties of the fields to be checked. It then checks each of the text boxes to see whether they have been filled in. If they have not, it changes the Tag property of the text box to ERROR. After it has checked all the appropriate fields, it loops through the Controls collection on the current form. Each time through the loop, it checks the Tag property of the current control to see whether its equal to ERROR. If it is equal to this value, the Text property of this text box is set to <Required>.
You should set up a constant in the General Declarations section called conRequired. This constant should have the value <Required> contained in it:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Const conRequired = "<Required>"
The reason for this is because youll use this constant in another location in this form. This way, if you want to change the text, you only need to change it in one location. After the code has looped through all the controls, it can then pop up a message box telling the user he or she needs to fill in all the text boxes marked with <Required>.

 
< previous page page_440 next page >

If you like this book, buy it!